<script>
	import {
		mapActions
	} from 'vuex'
	export default {
		async onLaunch() {
			const that = this
			this.getConfig()
			// uni.setStorageSync('token','eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIzMSIsImV4cCI6MTcyMDc1ODY0NH0.zxAEvsPSfeOpNl7e1GPz86crP-a2JP3A_hHxaPpvO0N609NFg7wDUT3F-iEpJrPD7E7q3BjNKLX594MVRb4Dhg')
			let token = uni.getStorageSync('token') || ''
			console.log(token, 'tokentoken')
			if (token) {
				await this.getUserinfo()
				await this.$utils.connectGoEasy(this.userInfo); //连接goeasy
				that.$isResolve()
			} else {
				that.$utils.wxLogin()
			}
			const updateManager = uni.getUpdateManager();
			updateManager.onCheckForUpdate(function(res) {
				// 请求完新版本信息的回调
				console.log('hasUpdate',res.hasUpdate);
			});
			updateManager.onUpdateReady(function(res) {
				uni.showModal({
					title: '更新提示',
					content: '新版本已经准备好，是否重启应用？',
					success(res1) {
						if (res1.confirm) {
							// 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
							updateManager.applyUpdate();
						}
					}
				});
			});
			updateManager.onUpdateFailed(function(res) {
				// 新的版本下载失败
			});
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		mounted() {
			
		},
		methods: {
			...mapActions(['getUserinfo','getConfig']),
			getUserIP(onNewIP) {
				let MyPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window
					.webkitRTCPeerConnection;
				let pc = new MyPeerConnection({
					iceServers: []
				});
				let noop = () => {};
				let localIPs = {};
				let ipRegex = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g;
				let iterateIP = (ip) => {
					if (!localIPs[ip]) onNewIP(ip);
					localIPs[ip] = true;
				};
				pc.createDataChannel('');
				pc.createOffer().then((sdp) => {
					sdp.sdp.split('\n').forEach(function(line) {
						if (line.indexOf('candidate') < 0) return;
						line.match(ipRegex).forEach(iterateIP);
					});
					pc.setLocalDescription(sdp, noop, noop);
				}).catch((reason) => {});
				pc.onicecandidate = (ice) => {
					if (!ice || !ice.candidate || !ice.candidate.candidate || !ice.candidate.candidate.match(ipRegex))
						return;
					ice.candidate.candidate.match(ipRegex).forEach(iterateIP);
				};
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	@import "@/uni_modules/uview-ui/index.scss";
	@import "@/common/common.scss";
	@import url('./static/style/chatInterface.css');
	// @import './static/style/common.css';

	/* 隐藏滚动条 */
	uni-scroll-view .uni-scroll-view::-webkit-scrollbar {
		display: none;
		width: 0 !important;
		height: 0 !important;
		-webkit-appearance: none;
		background: transparent;
		color: transparent;
	}

	.box_shadow {
		box-shadow: 0 10rpx 16rpx -10rpx #c1bfb4;
	}

	uni-button {
		margin-left: 0;
		margin-right: 0;
	}

	.nav1 {
		background-color: #F1F9F6;
		background-image: linear-gradient(to bottom, #c8fff1, #F1F9F6);
	}

	.nav2 {
		background-color: #FEF4E8;
		background-image: linear-gradient(to bottom, #FFEDB2, #FEF4E8);
	}

	.nav3 {
		background-color: transparent;
	}

	.order_time .u-count-down__text {
		font-size: 24rpx !important;
		color: #34314F !important;
	}

	.u-modal__content {
		text-align: center;
	}

	.wx {
		button {
			background: transparent;
			height: auto;
			width: auto;
			padding: 0;
			margin: 0;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		button::after {
			border: none;
		}
	}

	.comment .u-textarea {
		background-color: transparent !important;
	}

	.detail_nav .u-navbar__content__title {
		width: 0 !important;
	}

	.food uni-swiper .uni-swiper-dots-horizontal {
		bottom: 40px;
	}
	.u-popup__content{
		overflow: visible!important;
	}
	.close-modal{
		position: absolute;
		bottom: -100rpx;
		left: 0;
		width: 100%;
	}
</style>